#include "facevideopainteditem.h"
#include <qdebug.h>
#include "cameravideobuffer.h"
#include <QCameraInfo>
#include <QCamera>
#include <QVideoFrame>
#include <QPainter>
FaceVideoPaintedItem::FaceVideoPaintedItem(QQuickItem *parent)
    : QQuickPaintedItem(parent),mRunning(false)
{
    mpVideoBuffer=NULL;
}
void FaceVideoPaintedItem::paint(QPainter *painter)
{
    qDebug()<<"paint";
    if(NULL==mpVideoBuffer)
        return;

    QVideoFrame currentFrame;
    if(mpVideoBuffer && mpVideoBuffer->top(currentFrame)==false)
        return;

    QImage image(currentFrame.bits(),currentFrame.width(), currentFrame.height(),currentFrame.bytesPerLine(),QImage::Format_RGB888);

    painter->drawImage(boundingRect(),image.mirrored(true,false));
    mpVideoBuffer->Pop();
}
void FaceVideoPaintedItem::UpdateFrame(QVideoFrame frame)
{
    if(NULL==mpVideoBuffer)
        return;
    update();
}

